package com.hyzh.latte.vehicle.nezha;

import com.alibaba.fastjson.JSON;
import com.corundumstudio.socketio.SocketIOClient;
import com.hyzh.latte.vehicle.dmo.*;
import com.hyzh.latte.vehicle.dmo.entity.PositioningInfoEntity;
import com.hyzh.latte.vehicle.socket.EventType;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;
import java.util.Set;

/**
 * @author songkui
 * @since 2024/3/21 9:36
 */
@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(of = {"sessionId"})
@Slf4j
public class NezhaClient {

    private SocketIOClient client;
    private String sessionId;
    private String parkCode;

    private String userId;
    private String token;

    private Set<String> cameras; // 摄像头
    private boolean allCamera; // true 表示 当前端  传 ALL 则所有涉嫌偷

    private boolean vcs; //车辆轨迹  关闭 还是有效
    private boolean pcs;  //人员轨迹 关闭 或有效




    public void sendMessage(VehiclePathMessage message){
        if (vcs){
//            log.info("Send message: sid:{};  {} ", client.getSessionId(), JSON.toJSONString(message));
            client.sendEvent(EventType.PC_PUSH_VEHICLE_TRACK.event(), message);
        }

    }

    public void sendVehicleListMsg(VehicleListMessage message){
        if (vcs){
            client.sendEvent(EventType.PC_PUSH_VEHICLE_LIST.event(), message);
        }
    }
    public void sendVehiclePointMsg(VehiclePointMessage message){
        if (vcs){
            client.sendEvent(EventType.PC_PUSH_POINT_LIST.event(), message);
        }
    }

    public void sendDeleteMsg(VehicleDeleteMessage message){
        if (vcs){
//            log.info("Send delete vehicle message: sid:{};  {} ", client.getSessionId(), JSON.toJSONString(message));
            client.sendEvent(EventType.PC_PUSH_VEHICLE_DELETE.event(), message);
        }
    }


    public void sendPersonTrackMsg(Collection<PersonTrackDTO> data){
       if (pcs){
//           log.info("Send person track message: sid:{};  {} ", client.getSessionId(), JSON.toJSONString(data));
           client.sendEvent(EventType.PC_PUSH_PERSON_TRACK.event(), data);
       }
    }
    public void sendPersonTrackMsg(PersonTrackMessage data){
       if (pcs){
//           log.info("Send person track message: sid:{};  {} ", client.getSessionId(), JSON.toJSONString(data));
           client.sendEvent(EventType.PC_PUSH_PERSON_TRACK.event(), data);
       }
    }

    /**
     *
     * @param data 李斌--北京--胸针定位实体
     */
    public void sendLocationMsg(PositioningInfoEntity data){
        log.info("Send person track message: sid:{};  {} ", client.getSessionId(), JSON.toJSONString(data));
        client.sendEvent(EventType.PC_PUSH_PERSON_LOCATION.event(), data);
    }
}
